<?php

/*
* AES 算法
*/

class AES {

    private static $hex_iv = 'UcbCR28csxZI2YRklqHAog==';

    /*
    * 字符串加密 不写入文件
    */
    public static function encrypt($input, $key)
    {
        $hex_iv = env('HEX_IV', self::$hex_iv);
        $encrypted = openssl_encrypt($input, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, base64_decode($hex_iv));
        $encrypted = base64_encode($encrypted);

        return $encrypted;
    }

    /*
    * 字符串解密
    */
    public static function decrypt($input, $key)
    {
        $hex_iv = env('HEX_IV', self::$hex_iv);
        $decrypted = openssl_decrypt(base64_decode($input), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, base64_decode($hex_iv));
        return $decrypted;
    }


}
